
set scheme lean2
use "${altered_data}data_melde.dta", clear
gen early = inlist(idbundesland, 13, 2, 1, 11, 12, 5, 6, 7, 10)
keep if age == 0
expand 2, generate(total)
gen meldedatum2 = date
replace early = 2 if total == 1
lab def early 0 "Late" 1 "Early" 2 "Total"
lab val early early
gen cases = cases_melde_total
collapse (mean) cases[fw=pop], by(meldedatum2 early)
save "${altered_data}cases_meldedatum.dta", replace


xtset early meldedatum2
foreach var in cases {
	gen `var'_week = (`var' + L1.`var' + L2.`var' + L3.`var' + L4.`var' + L5.`var' + L6.`var')
}


keep if inrange(meldedatum2,td(01feb2021),td(30oct2021))



su cases_week
gen yarea = r(max)*1.25
local yarea = round(r(max)*1.1)
local text_height = r(max)*1.2 - 1
local text_height2 = r(max)*1.2 - 10

local x1 = td(01feb2021) + (td(03mar2021) - td(01feb2021))/2 //lockdown
local x2 = td(03mar2021) + (td(23mar2021) - td(03mar2021))/2 //partial openings
local x3 = td(23mar2021) + (td(21jun2021) - td(23mar2021))/2 //bundesnotbremse
local x4 = td(21jun2021) + (td(30jul2021) - td(21jun2021))/2 //begin https://www.schulferien.org/Schulferien_nach_Ferien/Sommerferien/sommerferien.html
local x5 = td(31jul2021) + (td(13sep2021) - td(31jul2021))/2 //end
local x6 = td(13sep2021) + (td(20oct2021) - td(13sep2021))/2 //after

local xt0 = td(01feb2021) 
local xt1 = td(03mar2021) 
local xt2 = td(23mar2021) 
local xt3 = td(21jun2021) 
local xt5 = td(31jul2021) 
local xt6 = td(13sep2021) 

tw ///
(area yarea meldedatum2 if inrange(meldedatum2,td(01feb2021),td(03mar2021)), color(gs15) lw(none)) ///
(area yarea meldedatum2 if inrange(meldedatum2,td(03mar2021),td(23mar2021)), color(gs8) lw(none)) ///
(area yarea meldedatum2 if inrange(meldedatum2,td(23mar2021),td(21jun2021)), color(gs10) lw(none)) ///
(area yarea meldedatum2 if inrange(meldedatum2,td(21jun2021),td(30jul2021)), color(gs12) lw(none)) ///
(area yarea meldedatum2 if inrange(meldedatum2,td(30jul2021),td(31jul2021)), color(gs8) lw(none)) ///
(area yarea meldedatum2 if inrange(meldedatum2,td(31jul2021),td(13sep2021)), color(gs12) lw(none)) ///
(area yarea meldedatum2 if inrange(meldedatum2,td(13sep2021),td(02nov2021)), color(gs15) lw(none)) ///
(line cases_week meldedatum2 if early == 2, lp(solid))  /// total
(line cases_week meldedatum2 if early == 1, lp(dash_dot))  /// early
(line cases_week meldedatum2 if early == 0, lp(dash))  /// late
, legend(pos(6) rows(1) order(8 9 10) lab(8 "Total") lab(9 "Early openings") lab( 10 "Late openings") size(small)) ///
ylabel(0(50)`yarea', nogrid labs(small)) xtitle("") xlabel(`xt0' `xt1' `xt2' `xt3' `xt5' `xt6' `xt7',labs(vsmall) format(%tdDDMonYY)) ///
text(`text_height' `x1' "fully closed", size(vsmall)) ///
text(`text_height' `x2' "partial", size(vsmall)) ///
text(`text_height2' `x2' "openings", size(vsmall)) ///
text(`text_height' `x3' "Bundesnotbremse", size(vsmall)) ///
text(`text_height2' `x3' "unified federal restrictions", size(vsmall)) ///
text(`text_height2' `x4' "start", size(vsmall)) ///
text(`text_height' `x4' "summer breaks", size(vsmall)) ///
text(`text_height2' `x5' "end", size(vsmall)) ///
text(`text_height' `x5' "summer breaks", size(vsmall)) ///
text(`text_height' `x6' "fully open", size(vsmall)) 



graph export "${plots}Timeline_schools.png", replace width(3000)
